"use strict";
const way = require("../utils/way");

/**
 * 会员
 * 
 * @param {mixnick: string} 	混淆昵称
 * @param {session: string} 
 */
exports.selectMember = async (cloud,session, mixnick) => {
  const data = {
    'mix_nick': mixnick
  };
  data.session = session;
  console.log("selectMember mixnick", mixnick);
  const results = await way.taobao(cloud, "taobao.crm.member.identity.get", data);
  const user = results.result.member_info;
  console.log("selectMember user", user);
  let res = { grade: 0 };
  if (user) {
    res.grade = user.grade;
  }
  return res;
};

/**
 * 会员入会地址
 * 
 * @param {string} callurl 回调url
 * @param {string}  info 扩展参数
 */
exports.selectJoinUrl = async (cloud, callurl, info) => {
  const data = {
    'callback_url': callurl,
    'extra_info': info
  };
  const results = await way.taobao(cloud, "taobao.crm.member.joinurl.get", data);
  const url = results.result;
  return url;
};

/**
 * 查询open_uid
 * 
 * @param {mixnick: string} 	混淆昵称
 */
exports.selectOpenUid = async (cloud, mixnick) => {
  const data = {
    'mix_nick': mixnick
  };
  console.log("selectOpenUid mixnick", mixnick);
  const results = await way.taobao(cloud, "taobao.openuid.get.bymixnick", data);
  console.log("selectOpenUid results", results);
  return results.open_uid;
};